home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / essent / FIXES / CSeries.exe / issue98 / CPROG1.CPP next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  5.0 KB  |  87 lines

  1. /* PROGRAM CPROG1.CPP
  2.  
  3.      Press Ctrl+F9 to compile and run this program.
  4.  
  5.      Press F5 to zoom the window. See the Window menu (Alt+W) for more
  6.      window-related commands. Also have a look at the Help system (Alt+H).
  7.      Note that F1 gives context-sensitive help. Now press the down cursor
  8.      key to put the dashed line at the top of the window
  9.      ----------------------------------------------------------------------
  10.      The next two lines are preprocessor commands. The first #include causes
  11.      the file STDIO.H to be read at that point. Then CONIO.H is read. It's
  12.      as though the contents of those two files replaced the #include lines
  13.      in which they are named.
  14.         Files that end in .H are called header files. They contain important
  15.      information that the compiler needs to know about ready-compiled library
  16.      functions. Header files can also store often-repeated information like
  17.      the definition of macros that you use time and again. Macros will
  18.      be covered in more detail another time. See #define under Help/Index
  19.      if you want to push ahead on this.
  20.         STDIO.H includes information about printf(), a function supplied
  21.      in the libraries accompanying TC Lite and used in this program.
  22.      Kbhit() is covered in CONIO.H. The on-line help will tell you which
  23.      header file you need to #include for a particular function.
  24.      Note how this comment spans several lines, yet only its start and
  25.      end points need to be indicated. */
  26.  
  27. #include <stdio.h>
  28. #include <conio.h>
  29.  
  30. main()
  31. {
  32.     /*------------------------------------------------------------------+
  33.     | The next lines use the printf() function to print a message       |
  34.     | NOTE:                                                             |
  35.     | - The ; character on the end of every C/C++ command.              |
  36.     | - The \n in the middle of the print string. The \ character       |
  37.     |   allows you to embed special codes within strings.               |
  38.     |   \n means 'new line'. \t is a tab. There are others.             |
  39.     | - That these comments are all ignored by the compiler because of  |
  40.     |   the enclosing slash-star and star-slash. The bordering -, + and |
  41.     |   | characters are purely optional embelishments.                 |
  42.     | - Comments cannot be placed within comments, which is why I had   |
  43.     |   to write slash-star and star-slash rather than the actual       |
  44.     |   characters - the compiler would get confused!                   |
  45.     +-------------------------------------------------------------------*/
  46.  
  47.     printf("Come on in\nThe C's lovely!");
  48.     printf("\n\nPress a key...\n");
  49.  
  50.     /*-----------------------------------------------------------------------+
  51.     | Note how the string to be printed is passed to the program code inside |
  52.     | printf() by putting it between the brackets. This mechanism for passing|
  53.     | parameters to functions will be covered later in the series.           |
  54.     +-----------------------------------------------------------------------*/
  55.  
  56.      // The next bit pauses program execution until you press a key.
  57.  
  58.     while ( kbhit() == 0 )
  59.       ;
  60.  
  61.     /*------------------------------------------------------------------+
  62.     | NOTE:                                                             |
  63.     | - How the single-line comment above just needed a preceding //    |
  64.     | - WHILE executes the command after it while the condition         |
  65.     |   inside the brackets is true. Since the while(...) construct     |
  66.     |   is immediately followed by a ; character and ; marks the end of |
  67.     |   a command, this loop doesn't have anything to do other than     |
  68.     |   continually test the condition.                                 |
  69.     | - kbhit() is a function supplied in a library with the compiler.  |
  70.     |   It tests whether or not a key has been pressed. If it hasn't,   |
  71.     |   it comes back with (returns) the number '0' meaning false. Put  |
  72.     |   the cursor anywhere in kbhit() and press Ctrl+Shift+F1 to read  |
  73.     |   more about it. Esc returns you here.                            |
  74.     | - == is a C operator meaning 'is equal to' and is used in equality|
  75.     |   tests only. A single = is used when you assign a value to a     |
  76.     |   variable.                                                       |
  77.     | - The line above therefore translates as:                         |
  78.     |   'If the number reported by the function kbhit() is equal to 0,  |
  79.     |    do nothing and repeat the test'                                |
  80.     +------------------------------------------------------------------*/
  81. }
  82.     /*--------------------------------------------------------------------+
  83.     | Program execution never gets this far... it automatically ends when |
  84.     | it meets the brace at the end of Main. Press Ctrl+F9 to compile and |
  85.     | run this program.                                                   |
  86.     +--------------------------------------------------------------------*/
  87.